import Opt from '@/components/dt/info/Opt.js'
import toolMgr from '@/biz/base/tool.js'
import ruleOpt from '@/biz/option/rule.js'

class NewOpt extends Opt {
  constructor(info) {
    super(info)
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      {
        key: 'orgId',
        title: '所属组织',
        col: 22,
        load: (o) => {
          toolMgr.organization().then((res) => {
            res = res.find((i) => i.orgName == '新房事业部')
            o.select.options =
              res && res.children
                ? res.children.map((i) => ({
                    key: i.orgId,
                    value: i.orgName
                  }))
                : []
          })
        },
        select: {
          options: []
        },
        rules: [ruleOpt.required('请选择所属组织')]
      },
      {
        title: '奖金单名称',
        placeholder: '请输入奖金单名称',
        key: 'bonusName',
        col: 22,
        input: {},
        rules: [ruleOpt.required('请输入奖金单名称'), ruleOpt.max(50)]
      },
      {
        title: '奖金单年份',
        placeholder: '请选择奖金单年份',
        key: 'bonusYear',
        col: 22,
        date: {
          type: 'year',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          }
        },
        rules: [ruleOpt.required('请选择奖金单年份')]
      },
      {
        title: '涉及月份',
        key: 'bonusStartMonth',
        group: [
          {
            key: 'bonusStartMonth',
            placeholder: '开始月份',
            col: 10,
            date: {
              type: 'month',
              format: 'MM'
            }
          },
          {
            col: 1,
            palceholder: '-',
            text: {}
          },
          {
            key: 'bonusEndMonth',
            placeholder: '结束月份',
            col: 10,
            date: {
              type: 'month',
              format: 'MM'
            }
          }
        ],
        rules: [
          ruleOpt.required('请选择涉及月份'),
          ruleOpt.check('请选择涉及月份', (val) => {
            return !val ^ !this.info.bonusEndMonth
          }),
          ruleOpt.check('结束月份不可小于开始月份', (val) => {
            return Number(val) > Number(this.info.bonusEndMonth)
          })
        ]
      }
    ]
  }
}

export default NewOpt
